// 数组
// let a1:number[]=[1,2,3]
let a1: Array<number> = [1, 2, 3]
// 接口
interface i1 {
    name: string,
    age?: number
}
interface i2 {
    // 可索引的类型
    [index: number]: string
}
function p1(a: i1) {
    console.log(a);

}
// ===类类型
interface Shape {
    color: string;
}

interface Square extends Shape {
    sideLength: number;
}

let square = <Square>{};
// let square = {} as Square;
square.color = "blue";
square.sideLength = 10;
// ====混合类型
interface Counter {
    (start: number): string;
    interval: number;
    reset(): void;
}

function getCounter(): Counter {
    let counter = <Counter>function (start: number) { };
    counter.interval = 123;
    counter.reset = function () { };
    console.log(counter.interval, "=counter");

    // console.log(counter.interval,"=counter");

    return counter;
}

let c = getCounter();
c(10);
c.reset();
c.interval = 5.0;
// console.log(c,"====",c(10)  );
// ====泛型
console.log(c, "====", c(10));







function identity<T>(arg: T): T {
    console.log(arg);
    return arg
}
identity(1)
// 泛型类型
let myIdentity: <T>(arg: T) => T = identity;
// 泛型类
class Cls1<T>{
    name?: T;
    age?: (x: T, y: T) => T;
}
let ar = new Cls1<number>()
ar.name = 0;
ar.age = function (x, y) { return x + y; };
// 枚举
enum Direction {
    Up = 1,
    Down,
    Left,
    Right
}
console.log(Direction);
//交叉leixing 
class c1 {
    name?: string
}
interface Bird {
    fly: () => {};
    layEggs: () => {};
}


interface Interface {
    num: number;
}
declare function aliased(arg: Alias): Alias;
declare function interfaced(arg: Interface): Interface;
// let arr: ;
interface Fish {
    swim: () => {};
    layEggs: () => {};
}

function getSmallPet(): Fish | Bird {
    // ...
    return {} as any
}

let pet = getSmallPet();
pet.layEggs(); // okay
// pet.swim();    // errors


class C1 {
    a: number | undefined;
    b?: number;
}
let c2 = new C1();
c2.a = 12;
c2.a = undefined; // error, 'undefined' is not assignable to 'number'
c2.b = 13;
c2.b = undefined; // ok
// c2.b = null; // error, 'null' is not assignable to 'number | undefined'

type Alias = { num: number }
interface Interface {
    num: number;
}
declare function aliased(arg: Alias): Alias;
declare function interfaced(arg: Interface): Interface;
export { }